//Importing data and variable renaming//
ssc install estout
use unemployment
label variable coopscreated "Number of Co-ops created" 
label variable unemployment "Unemployment increase"
label variable aftercrisis "Disaffection with capitalism"
label variable year "Year"
//The model and table and some diagnostic work//
sum coopscreated, detail
reg coopscreated unemployment aftercrisis
est store model1
estadd vif
predict cook, cooksd
sum cook
tab cook
esttab model1, cells("b(fmt(2)) se(fmt(2)) vif(fmt(2)) p(fmt(3))") scalars(r2 rmse) nomtitles nonumbers noconstant label not title(Table 2. Unemployment-Dissaffection model for cooperative creation), using Table1.rtf, replace
//Estimating prediction and out of sample errors//
predict residual, resid
forvalues i = 1/19 {

quietly reg coopscreated unemployment aftercrisis if id !=`i'
predict a`i', resid, if id == `i'
}
egen outofsample = rowmax(a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19)

forvalues i = 1/19 {
drop a`i'
}

//Table for perdiction and out of sample errors//
replace residual=round(residual, 0.01)
replace outofsample=round(outofsample, 0.01)
gsort year unemployment aftercrisis residual outofsample
mkmat year unemployment aftercrisis residual outofsample, mat(table2) nomissing
svmat float table2
esttab matrix(table2), title(Table 3. Individual Prediction and Out of sample errors for the Unemployment-Dissaffection model) ,using table2.rtf, replace





